//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    internal class TableBackgroundStyle : IOfficeXmlSerializable
    {
        private FillProperties fill;
        private EffectProperties effect;
        private StyleMatrixReference fillRef;
        private StyleMatrixReference effectRef;
        internal const string xmlName = "tblBg";

        #region IOfficeXmlSerializable Members

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                this.fill = FillProperties.ReadFillProperties(c);
                if (this.fill == null)
                {
                    fillRef = c.ReadElementAs<StyleMatrixReference>("fillRef");
                }
                this.effect = EffectProperties.ReadEffectProperties(c);
                if (effect == null)
                    this.effectRef = c.ReadElementAs<StyleMatrixReference>("effectRef");
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.WriteOptionalElement(fill);
                c.WriteOptionalElementAs(fillRef, "fillRef");
                c.WriteOptionalElement(effect);
                c.WriteOptionalElementAs(effectRef, "effectRef");
            }
        }

        #endregion
    }
}